using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ExcellOnServices.Models.Mapping
{
    public class ProductMap : EntityTypeConfiguration<Product>
    {
        public ProductMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Name)
                .IsRequired();

            this.Property(t => t.ImageUrl)
                .IsRequired();

            this.Property(t => t.Price)
                .IsRequired();

            // Table & Column Mappings
            this.ToTable("Products");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.ImageUrl).HasColumnName("ImageUrl");
            this.Property(t => t.Price).HasColumnName("Price");
            this.Property(t => t.Discount).HasColumnName("Discount");
            this.Property(t => t.Description).HasColumnName("Description");
            this.Property(t => t.Properties).HasColumnName("Properties");
            this.Property(t => t.CreatedDateTime).HasColumnName("CreatedDateTime");
            this.Property(t => t.ModifiedDateTime).HasColumnName("ModifiedDateTime");
            this.Property(t => t.Company_Id).HasColumnName("Company_Id");
            this.Property(t => t.Category_Id).HasColumnName("Category_Id");

            // Relationships
            this.HasRequired(t => t.Accounts_Company)
                .WithMany(t => t.Products)
                .HasForeignKey(d => d.Company_Id);
            this.HasRequired(t => t.Category)
                .WithMany(t => t.Products)
                .HasForeignKey(d => d.Category_Id);

        }
    }
}
